package nc.ui.medpub.pub.billwithinv;

import nc.ui.trade.bsdelegate.BusinessDelegator;
import nc.vo.medpub.pub.MedInvSuperVO;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.scm.ic.bill.InvVO;

public class BillWithInvDelegator extends BusinessDelegator {
	
	@Override
	public CircularlyAccessibleValueObject[] queryBodyAllData(Class voClass, String billType, String key,
			String strWhere) throws Exception {
		
		CircularlyAccessibleValueObject[] vos = super.queryBodyAllData(voClass, billType, key, strWhere);
		setInvFreeInfo(vos);
		return vos;
	}
	
	protected void setInvFreeInfo(CircularlyAccessibleValueObject[] vos) {
		if (vos == null || vos.length == 0) {
			return;
		}
		if (vos[0] instanceof MedInvSuperVO) {
			InvVO[] invs = new InvVO[vos.length];
			for (int i = 0; i < vos.length; i++) {
				invs[i] = ((MedInvSuperVO) vos[i]).getInvVO();
			}
			MedInvHelper.setInvInfo(invs);
			for (int i = 0; i < vos.length; i++) {
				((MedInvSuperVO) vos[i]).setFreeItemVO(invs[i].getFreeItemVO());
			}
		}
	}
	
}
